package com.yigang.homecontroller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.yigang.entity.Product;
import com.yigang.entity.User;
import com.yigang.utils.ResultUtil;
import com.yigang.utils.UserConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.yigang.service.ActivityService;
import com.yigang.service.ClassificationService;
import com.yigang.service.ProductService;

@Controller
public class IndexController {
    @Autowired
    ClassificationService classificationService;
    @Autowired
    ActivityService activityService;
    @Autowired
    ProductService productService;

    @RequestMapping("/index")
    public String indexa(Model model, HttpSession session, String searchKey,Integer classificationId) {
//        List<Map<String, Object>> list = classificationService.getAll();
//        List<Map<String, Object>> list1 = activityService.getAllActivity();
        List<Map<String, Object>> list2 = productService.getAllproduct(searchKey,classificationId);
//        System.out.println(list);
//        System.out.println(list1);
        System.out.println(list2);
//        model.addAttribute("list", list);
//        model.addAttribute("list1", list1);
        model.addAttribute("list2", list2);
        model.addAttribute("searchKey", searchKey);
        return "jsp/home/index";

    }

    @RequestMapping("/header")
    public String header(Model model, HttpSession session) {
        List<Map<String, Object>> list3 = classificationService.getAll();
        model.addAttribute("list3", list3);
        return "jsp/home/header";
    }

    @RequestMapping("/productList")
   	public String productList(Model model, HttpSession session,
   			String searchKey,Integer classification_id/* ,@RequestParam("classification_id") Integer classification_id */) {
           List<Map<String, Object>> list4 = productService.getAllproduct(searchKey,classification_id);
//           Product list = productService.getAllproductById(classification_id);
           System.out.println(list4);

           model.addAttribute("list4", list4);
//           model.addAttribute("list", list);
           return "jsp/home/productList";
       }
   
}
